﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MvcMasterPage
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            /* 将进行了约束的路由放在上面，否则它将会最上面的没有被限制的路由所覆盖
             * 我们看到的，越靠上面的路由被约束的条件越严格
             *  一般地：对于一个Action可能出现多个参数规则时，我们将完整的参数写在最上面
             * 然后，由多到少向下写，路由会根据参数多少去匹配，当你转2个参数时，它不会把3个参数的路由匹配上，而如果你
             * 但是，如果你传3个参数，它会把2个参数的路由匹配上，所以，我们把参数多的路由规则写在上面
             */

            routes.MapRoute("Default11"
                , "{controller}/{action}/{menuID}-{name}-{page}.shtml"
                , new { controller = "Home", action = "Index" });

            routes.MapRoute("Default111"
                , "{controller}/{action}/{name}-{page}.shtml"
                , new { controller = "Home", action = "Index" }
                , new { controller = "Home", action = "Index" });

            routes.MapRoute("Default1111"
                , "{controller}/{action}/{id}-{page}.shtml"
                , new { controller = "Home", action = "Index" });

            routes.MapRoute(
                "Default1"
                , "{controller}/{action}/{id}.shtml"
                , new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                , new { action = "Edit" });

            routes.MapRoute("Default0"
                , "{controller}/{action}/{page}.shtml"
                , new { controller = "Home", action = "Index" });

            routes.MapRoute("Default"
                , "{controller}/{action}/{id}"
                , new { controller = "Home", action = "Index", id = UrlParameter.Optional });

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}